package com.song.debp.controller;

import com.song.common.entity.R;
import com.song.debp.domain.Dept;
import com.song.debp.service.DeptService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @author TonySong
 * @date 2024/4/27 0027
 * @time 13:55
 */
@RestController
@RequestMapping("/dept")
@Slf4j
public class DeptController {

    @Value("${server.port}")
    private Integer port;
    @Resource
    private DeptService deptService;

    @GetMapping("/")
    public R getDept(){
        log.info("dept port: {}", port);
        return new R(200,"ok", true, deptService.list());
    }
    @GetMapping("/{id}")
    public R getDeptById(@PathVariable("id") Long id){
        return new R(200,"ok", true, deptService.getById(id));
    }

    @PostMapping("/")
    public R addDept(@RequestBody Dept dept){
        return new R(200,"ok", true, deptService.save(dept));
    }

    @PutMapping("/")
    public R updateDept(@RequestBody Dept dept){
        return new R(200,"ok", true, deptService.updateById(dept));
    }

    @DeleteMapping("/{id}")
    public R deleteDept(@PathVariable("id") Long id){
        return new R(200,"ok", true, deptService.removeById(id));
    }

}
